package com.sisgh.jefdv1.cmd.command.has.arg.argument;

import com.sisgh.jefdv1.cmd.command.has.arg.argument.properties.ArgumentProperties;
import com.sisgh.jefdv1.util.CollectionUtils;

import java.util.List;

public abstract class AbstractArgument implements Argument{

    protected String longName;
    protected String shortName;
    protected List<String> values;
    protected String defaultValue;
    private final boolean required;

    public AbstractArgument(ArgumentProperties properties) {
        this.longName = properties.longName();
        this.shortName = properties.shortName();
        this.defaultValue = properties.defaultValue();
        this.required = properties.required();
    }

    public AbstractArgument(String longName,
                            String shortName,
                            boolean required) {
        this.longName = longName;
        this.shortName = shortName;
        this.required = required;
    }

    public AbstractArgument(String longName,
                            String shortName,
                            String defaultValue,
                            boolean required) {
        this.longName = longName;
        this.shortName = shortName;
        this.defaultValue = defaultValue;
        this.required = required;
    }

    @Override
    public boolean isEmpty() {
        return values == null || values.isEmpty();
    }

    @Override
    public List<String> values() {
        return values;
    }

    @Override
    public boolean required() {
        return required;
    }

    @Override
    public boolean valueRequired() {
        return defaultValue == null;
    }

    @Override
    public void values(List<String> values) {
        this.values = values;
    }

    @Override
    public boolean hasValues() {
        return !CollectionUtils.isEmpty(values);
    }
}
